package com.dries.security.core.config;

import com.dries.security.core.properties.SecurityCoreConstants;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description: 表单登录配置
 * @Author ZSY
 * @createTime 2020/9/11 10:33
 */
@Component
public class FormAuthenticationConfig {

    @Resource
    private AuthenticationSuccessHandler driesAuthSuccessHandler;
    @Resource
    private AuthenticationFailureHandler driesAuthFailureHandler;
    /**
     * 密码登录配置
     * @param http
     * @throws Exception
     */
    public void configure(HttpSecurity http) throws Exception {
        http.formLogin()
                .loginPage(SecurityCoreConstants.DEFAULT_UNAUTHENTICATION_URL)
                .loginProcessingUrl(SecurityCoreConstants.DEFAULT_LOGIN_PROCESSING_URL_FORM)
                .successHandler(driesAuthSuccessHandler)
                .failureHandler(driesAuthFailureHandler);
    }

}
